home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
pcr
/
pcr4_4.lha
/
DIST
/
loading
/
StripXSubsecs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-03
|
3KB
|
129 lines
/*
* StripXSubsecs.c
*
* Demers, October 2, 1990 10:12:27 am PDT
*/
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/file.h>
#include <xr/ADotOutExtrasAccess.h>
int
MyLSeekProc(offset, whence, fd)
int offset, whence, fd;
{
int ans = lseek(fd, offset, whence);
return ((ans == -1) ? -errno : ans );
}
int
MyFTruncateProc(offset, whence, fd)
int offset, whence, fd;
{
int ans;
if( whence != L_SET ) return (-EINVAL);
ans = ftruncate(fd, offset);
return ((ans == -1) ? -errno : ans );
}
int
MyReadProc(buf, bytes, fd)
char *buf;
int bytes, fd;
{
int ans = read(fd, buf, bytes);
return ((ans == -1) ? -errno : ans );
}
int
MyWriteProc(buf, bytes, fd)
char *buf;
int bytes, fd;
{
int ans = write(fd, buf, bytes);
return ((ans == -1) ? -errno : ans );
}
int global_argc = 0;
char **global_argv = NULL;
int vflag = 0;
Usage()
{
printf("Usage: %s [-v] [-m magic] objFileName\n", global_argv[0]);
exit(1);
}
ReportError(fmt, x1, x2, x3)
char *fmt;
int x1, x2, x3;
{
printf("\n%s: error: ", global_argv[0]);
printf(fmt, x1, x2, x3);
putchar('\n');
Usage();
}
void
main(argc, argv)
int argc;
char **argv;
{
int objfd;
char *objfn;
int i;
int ans;
global_argc = argc;
global_argv = argv;
if( argc < 2 ) Usage();
objfn = argv[argc-1];
argc -= 1;
if( access(objfn, R_OK|W_OK) != 0 )
ReportError("can't write %s\n", objfn, 0, 0);
i = 1;
while( i < argc ) {
if( strcmp(argv[i], "-v") == 0 ) {
vflag = 1;
i += 1;
continue;
}
if( (i+1) >= argc ) {
ReportError("%s: wrong # args\n", argv[i], 0, 0);
}
if( strcmp(argv[i], "-m") == 0 ) {
(void)XR_SetADotOutExtraMagic(atoi(argv[i+1]));
i += 2;
continue;
}
ReportError("bad flag %s\n", argv[i]);
}
if( vflag ) {
printf("Stripping %s ... \n", objfn);
}
objfd = open(objfn, O_RDWR, 0);
if( objfd == -1 )
ReportError("can't open %s\n", objfn);
ans = XR_DeleteAllExtraSubsecs(
MyLSeekProc, MyReadProc, MyWriteProc, MyFTruncateProc, objfd );
if( ans < 0 ) {
ReportError("can't delete subsecs from %s, err %d",
objfn, (-ans), 0 );
}
if( vflag ) {
printf(" done.\n");
}
(void)close(objfd);
exit(0);
}